//
//  IndexPage.m
//  Dolphin
//
//  Created by Handymood on 11-6-6.
//  Copyright 2011 __Hanydmood__. All rights reserved.
//

#import "IndexPage.h"


@implementation IndexPage

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) 
    {
        // Initialization code
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

//init method for bottom index 
-(void) initWithInfoObject:(IndexPageInfo *) indexPageInfo
                 columnNum:(int) inColumnNum 
                      rowNum:(int) inRowNum
{
    int units_num = [indexPageInfo.unitArr count];
    CGFloat start_off_x = indexPageInfo.start_unit_offset_x;
    CGFloat start_off_y = indexPageInfo.start_unit_offset_y;
    CGFloat unit_width = indexPageInfo.unit_width;
    CGFloat unit_height = indexPageInfo.unit_height;
    CGFloat unit_between_width = indexPageInfo.unit_between_width;
    
    self.contentSize = CGSizeMake(start_off_x+(unit_width+unit_between_width)*inColumnNum,unit_height);
    //self.bounces = FALSE;
    UIColor *greyBackColor = [[UIColor alloc] initWithWhite:0 alpha:0.75];
    [self setBackgroundColor: greyBackColor];
    [greyBackColor release];
    
    for (int i=0; i<units_num; i++) 
    {
        UIImageLayer*uiImageView =[[UIImageLayer alloc] initWithFrame:CGRectMake
                                   (start_off_x+i*(unit_width+unit_between_width) ,start_off_y, unit_width,unit_height-start_off_y)];
        
        if(indexPageInfo.targetPageIdArr != Nil &&
           i < [indexPageInfo.targetPageIdArr count] && 
           [indexPageInfo.targetPageIdArr objectAtIndex:i] != Nil)
        {
            uiImageView.button_id = [[indexPageInfo.targetPageIdArr objectAtIndex:i] intValue];
        }
        else
        {
            uiImageView.button_id = i;
        }
        
        [uiImageView initImage:[indexPageInfo.unitArr objectAtIndex:i] useOriginalSize:FALSE ratioMode:2 layerInfo:Nil ]; 
        
        [uiImageView initHitMsg:@"page_id_trigger"];
        [self addSubview:uiImageView];
    } 
}

-(void) reset
{
    for (UIImageLayer*singleView in[self subviews]) 
    {
        [singleView removeFromSuperview];
        if (singleView != Nil && [singleView isKindOfClass:[UIImageLayer class]]) 
        {
            [singleView reset];
        }
    }
}

- (void)dealloc
{
    [super dealloc];
}

@end
